package com.big.patient.controller;

import com.big.common.result.Result;
import com.big.model.model.patient.address.PatientAddress;
import com.big.model.vo.patient.PatientAddressVo;
import com.big.patient.service.PatientAddressService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/patient/address")
public class PatientAddressController {

    @Autowired
    PatientAddressService patientAddressService;

    //添加地址
    @ApiOperation(value = "添加地址")
    @PostMapping("/saveAddress")
    public Result saveAddress(@RequestBody PatientAddressVo patientAddressVo){
        Integer integer = patientAddressService.savePatientAddress(patientAddressVo);
        return  Result.ok(integer);
    }


    //查询地址
    @ApiOperation(value = "查询地址")
    @GetMapping("/info/{id}")
    public PatientAddress addressInfo(@PathVariable("id") Long id){
        PatientAddress patientAddress = patientAddressService.PatientAddressInfo(id);
        return  patientAddress;
    }


    //ip截取省市区
    @ApiOperation(value = "ip截取省市区")
    @PostMapping("/spliceAddress/{ipAddress}")
    public Result dictAddressIp(@PathVariable String ipAddress){
        Map<String, String> stringList = patientAddressService.dictAddressIp(ipAddress);
        return Result.ok(stringList);
    }

    //查询地址
    @ApiOperation(value = "查询地址")
    @GetMapping("/infos/{uId}")
    public Result patientAddressesInfos(@PathVariable("uId") Long uId){
        List<PatientAddress> patientAddresses = patientAddressService.patientAddressInfos(String.valueOf(uId));
        return  Result.ok(patientAddresses);
    }
}
